package com.store.app.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.HPTOpenDetailPeopleBean;

import java.util.List;

/**
 * author lushan
 * on 2017/3/24 0024 14:46
 */

public class HPTOpenDetailAdapter extends BaseAdapter {

    private List<HPTOpenDetailPeopleBean.ListBean> mList;
    private Context mContext;

    public HPTOpenDetailAdapter(Context context, List<HPTOpenDetailPeopleBean.ListBean> list) {
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        Holder holder = null;
        if (view == null) {
            holder = new Holder();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_hpt_open_detail, null);
            holder.txt_phone = (TextView)view.findViewById(R.id.txt_phone);
            holder.txt_name = (TextView)view.findViewById(R.id.txt_name);
            holder.txt_statue = (TextView)view.findViewById(R.id.txt_statue);
            holder.txt_order_number = (TextView)view.findViewById(R.id.txt_order_number);
            holder.txt_create_time = (TextView)view.findViewById(R.id.txt_create_time);
            holder.txt_code = (TextView)view.findViewById(R.id.txt_code);
            holder.tv_address = (TextView)view.findViewById(R.id.tv_address);
            view.setTag(holder);
        } else {

            holder = (Holder) view.getTag();

        }
        HPTOpenDetailPeopleBean.ListBean bean=mList.get(position);
        holder.txt_phone.setText(bean.getContact_tel());
        holder.txt_name.setText(bean.getContact_person());
        holder.txt_order_number.setText(bean.getOrder_no());
        holder.txt_create_time.setText(bean.getOrder_date());
        holder.txt_code.setText(bean.getLoaded_code());
        holder.txt_statue.setText(hptOrderStatus(bean.getStatus()));
        if(TextUtils.isEmpty(bean.getAddress())){
            holder.tv_address.setText("未知");
        }else{
            holder.tv_address.setText(bean.getAddress());
        }
        return view;
    }

    class Holder {
        TextView txt_phone;//手机号码
        TextView txt_name;//名字
        TextView txt_statue;//订单状态
        TextView txt_order_number;//订单号码
        TextView txt_create_time;//创建时间
        TextView txt_code;//提货码
        TextView tv_address;//收货地址
    }
    //伙拼团订单状态
    public static String hptOrderStatus(String status){
        if("paid".equals(status)){
            return "已支付";
        }else if("received".equals(status)){
            return "已收货";
        }else if("cancelled".equals(status)){
            return "已取消";
        }else if("refunded".equals(status)){
            return "已返款";
        }else if("delivered".equals(status)){
            return "已发货";
        }
        return "";
    }
}
